home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Author: Markus van Kempen
- ** Date : 17 Nov 1992
- **
- ** File : Stack-Language.c
- **
- ** (c) by VIONA-Development 1992/93
- **
- **
- ** HOW TO USE THE INTUIGFX STACK-LANGUAGE
- **
- **
- ** This is an expamle for IntuiGfx.
- ** The IntuiGfx.h includes a stack language.
- ** This language is used for drawing, building gadgets,
- ** menus a.s.o.
- **
- ** You can use (call/run) the stack-language in serveral ways.
- **
- ** 1. In structures as little programs
- ** 2. With the interpeter "EI_Interpret" a.s.o.
- **
- ** The stack language has many functions and commands
- ** (see IntuiGfx.h and IntuiGfx.doc).
- **
- ** Please read the IntuiGfx.doc to understand how
- ** the stack-language works and see the following paragraph.
- **
- ** To help you to use the language for your own application
- ** we want to build an example.
- **
- ** We build a BoolGagdet with a triangle in it.
- ** At first you should know how to open a EGS-Window, because
- ** we need a window to display the gadget.
- **
- ** If you have a window structure, you should give
- ** the address of the BoolGadget to the window
- ** before you open it. Like:
- **
- ** newwin.gadgets=&myBoolGadget;
- **
- ** At first we make a normale triangle.
- ** For this work we need the following commands:
- **
- ** IG_CDark = Get the dark color and put it on the stack
- ** IG_Color = Set color dark (first stack parameter)
- **
- ** IG_GETFI+0 = Get the 0. frame parameter and put it on the stack
- ** IG_GETFI+1 = Get the 1. frame parameter and put it on the stack
- **
- ** IG_Const+2 = Put 2 on the stack
- ** IG_IDIV = Divide parameter[stack-1] / para[stack-0]
- ** Like: IG_GETFI+0,IG_Const+2,IG_IDIV,
- ** X , 2 , / (like HP)
- ** IG_Move = Move the cursor to the pos. stack-1,stack-0
- ** IG_Draw = Draws a line from the current pos. the
- ** pos. stack-1,-stack-0
- **
- ** IG_NEG = Negation from the stack parameter - 0
- **
- ** IG_RTF+2 = Remove 2 frameparamter and returns to the caller
- **
- **
- ** Here comes the routine:
- **
- **
- ** IntuiGfx:
- **
- ** "Triangle" draws a triangle in a frame given by
- ** width an height. In the following description
- ** is shown how the routine draws the triangle.
- ** To understand it, please think like a plotter
- ** and take the positions as relative coordinates.
- **
- ** Triangle positions are:
- **
- ** POS X Y
- **
- ** 1 = width/2 , height/2 | Move to the position
- **
- ** 2 = -width/2 , height/2 | Draw to the position
- **
- ** 3 = width , 0 | Draw
- **
- ** 4 = -width/2 , -height/2 | Draw
- **
- **
- ** 0 Location
- ** 0############ ------> + x
- ** | BOX | |
- ** / | 1,4 | |
- ** h | /\ | |
- ** \ | / \ | |
- ** | 2------3 |-- \/
- ** | dx |dx + y
- ** ############--
- ** |dx| |dx|
- ** ** dx is use in the second part !
- ** \ /
- ** w
- **
- ** STACK for Input:
- ** +1 = width
- ** +0 = height
- **
- */
-
- ULONG triangle [] = {
- /* NO.*/
- /* 1 */ IG_CTxtFront,IG_Color, /* Set Color */
- /* 2 */ IG_GETFI+1,IG_Const+2,IG_IDIV, /* width / 2 = x */
- /* 3 */ IG_GETFI+0,IG_Const+2,IG_IDIV, /* height/ 2 = y */
- /* 4 */ IG_Move, /* move to Pos x,y */
-
- /* 5 */ IG_GETFI+1,IG_Const+2,
- /* 6 */ IG_IDIV,IG_NEG, /* (width / 2)*(-1) = x */
- /* 7 */ IG_GETFI+0,IG_Const+2,IG_IDIV, /* (height/ 2) = y */
- /* 8 */ IG_Draw,
-
- IG_GETFI+1,IG_Const+0,IG_Draw, /* x= width, y = 0 */
-
- IG_GETFI+1,IG_Const+2,
- IG_IDIV,IG_NEG,
- /* (width / 2)*(-1) = x */
- IG_GETFI+0,IG_Const+2,
- IG_IDIV,IG_NEG,
- /* (height/ 2)*(-1) = y */
- IG_Draw,
-
- /*
- ** for using only this routine in gadget structure please replace
- **
- ** IG_RTF+2 with IG_RTS
- */
-
- IG_RTF+2 /* Remove parameter, */
- }; /* and returns */
-
- /*
- ** To test the routine please change the line in the
- ** gadget structure at the end of the text and compile it.
- **
- ** (IG_IntuiGfxPtr) &triangle, * active *
- **
- ** Please play with the routine and his parameter.
- ** For example:
- ** Change the height to bring the triangle
- ** in the top of the gadget
- ** see line 3
- ** IG_GETFI+0,IG_Const+20,IG_IDIV,
- ** ^^
- ** a.s.o. ....
- **
- **
- ** 2. The next step is
- **
- ** We want that the triangle routine uses a specified
- ** distance from the gadget border.
- **
- ** For this work we need the parameter dx (see upper).
- ** dx tells us the distance from the triangle to the bottom and
- ** border of the gadget.
- **
- ** Commands are used:
- **
- ** IG_Locate00 = locate to 0,0
- **
- ** IG_Locate = locate to x,y [stack-1,stack-0]
- **
- ** IG_JSR = jump to the sub routine on the parameter stack-0
- **
- **
- **
- ** The algorithm is:
- **
- ** We locate the cursor to a new position (dx/2,dx/2).
- ** x , y
- ** then we substitude dx from the width,height
- ** and call the triangle routine.
- **
- ** call triangle to draw.
- **
- ** see below:
- **
- */
-
- /*
- **
- ** IntuiGfx
- **
- ** Prepaed the parameter for triangle.
- ** Set the locations for the zero point.
- ** And subs the offset from the frame (width,height).
- **
- ** This give us the posibilities of scalable gadgets.
- **
- **
- ** STACK:
- ** 0 = height
- ** 1 = width
- ** 2 = dx
- **
- **/
-
- ULONG sc_triangle [] = {
- IG_GETFI+2,IG_Const+2,IG_IDIV,
- IG_GETFI+2,IG_Const+2,IG_IDIV,
- IG_Locate,
- IG_GETFI+1,IG_GETFI+2,IG_SUB,
- IG_GETFI+0,IG_GETFI+2,IG_SUB,
- (ULONG)&triangle,IG_JSR,IG_Locate00,
- IG_RTF+3};
- /*
- **
- ** But at first we must build a calling routine
- ** with the parameter dx.
- **
- ** The algo.
- **
- ** 1. Locate to 0,0
- **
- ** 2. Put the offset on the stack
- ** (dx must mod 2, because we divide the int by 2)
- **
- ** 3. put width on the stack
- **
- ** 4. put height on the stack
- **
- ** 5. call sc_triangle
- **
- ** Here comes the routine for the algo.
- **
- */
-
- /*
- ** IntuiGfx - routine for marking selected menu item
- ** 1 0
- ** ( width, height)
- */
-
- ULONG myGFX [] ={
- IG_Locate00,
- IG_Const+64, /* Offset from the border */
- IG_GETFI+1,
- IG_GETFI+0,
- (ULONG)&sc_triangle,IG_JSR,
- IG_RTS};
-
-
- /*
- ** --------------------------------------------------------------
- **
- ** To test the routine please change the line in the
- ** gadget structure at the end of the text and compile it.
- **
- ** (IG_IntuiGfxPtr) &myGFX, * active *
- **
- ** Make changes with the offset and see what happens.
- **
- **
- ** 3.
- **
- ** The thrid step is to make a scaleable Gadget.
- ** That means a gadget is automatical resizing
- ** its image, if you size the window, for example.
- **
- ** For doing this work append the following lines to
- ** the event handling from the window.
- **
- case EI_iSizeVerify:
-
- printf("VerifySizing ! \n");
-
- EI_RemoveGadget(Window,(struct EI_Gadget *)&myBoolGadget);
-
- ReplyMsg ( (struct Message *)imess );
- break;
-
- case EI_iWindowSize:
-
- printf("Sizing ! \n");
-
- EI_LockIntuition();
-
- myBoolGadget.class.width = Window->width-
- myBoolGadget.class.leftEdge*2;
- myBoolGadget.class.height = Window->height-
- myBoolGadget.class.topEdge*2;
- * *2 for the border *
-
- EI_AddGadget(Window,(struct EI_Gadget *)&myBoolGadget);
-
- EI_UnlockIntuition();
-
- ReplyMsg((struct Message *)imess);
- break;
-
- **
- ** It is very easy, if the windowing is sizing (see VerifySizing)
- ** we remove the BoolGadget and get a clean window.
- **
- ** We wait for sizing finish. Then we LockEGSIntui so that nothing
- ** can happens.
- **
- ** After this we get from the window structure the new window size
- ** and put it in the BootGadget structure.
- **
- ** Then we add the gadget to the window and UnlockEGSIntui.
- **
- ** This is one way to make resizeable gadgets a other but the
- ** same base is to use the egsgadbox.library functions.
- ** (see egsgadbox.doc)
- **
- */
-
- /************************** TEST GADGET *************************/
-
- struct EI_BoolGadget myBoolGadget = {
-
- /* Gadget structure */
-
- {
- NULL,NULL, /* prev,next */
- 0,0, /* checkTop,leftEdge*/
- 10,10, /* leftEdge,topEdge */
- WIN_WIDTH -20,
- WIN_HEIGHT-20,
- /* width , height */
- 0x111, /* id */
-
- /*
- (IG_IntuiGfxPtr) &triangle,
- */
- (IG_IntuiGfxPtr) &myGFX, /* active */
- NULL, /* pasive */
- NULL, /* select */
- NULL, /* release */
-
- EI_STD_COMPLEMENT | /* flags */
- EI_STD_HIGHLIGHT |
- EI_REL_VERIFY |
- EI_TOGGLE_SELECT ,
-
- EI_BOOL_GADGET, /* Type */
- 'A', /* hotkey */
- NULL, /* Call */
- NULL /* Userdata */
- },
-
- 1, /* flags=True */
- /* (use the Gadgetflags */
- 0,0,0, /* 3 pads */
- NULL, /* EI_GadgetArrayPtr*/
- NULL /* exclude,include */
- };
- /*
- */
-
-
-
-